/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.model;

import br.com.foxline.enums.AnualCorrection;
import br.com.foxline.enums.DiscountType;
import br.com.foxline.enums.PaymentType;
import br.com.foxline.enums.StatusSale;
import br.com.foxline.validator.CPF;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;

/**
 *
 * @author luciano
 */
@Entity
public class Sale implements Serializable{
    
    @Id
    @SequenceGenerator(sequenceName = "seq_sale", name = "seq_sale", allocationSize = 1)
    @GeneratedValue(generator = "seq_sale", strategy = GenerationType.SEQUENCE)
    private Long id;
    
    @ManyToOne(fetch= FetchType.EAGER)
    private Customer customer;
    
    private String nameOfReference1;
    private String phoneOfReference1;
    private String nameOfReference2;
    private String phoneOfReference2;
    
    private String observation;
    
    @ManyToOne(fetch= FetchType.EAGER)
    private Enterprise enterprise;
    @ManyToOne
    private Lot lot;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date saleDate;
    
    @Column(scale= 2, precision=19)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 2, integer = 10 )
    private BigDecimal totalValue;
    
    @Column(scale= 2, precision=19)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 2, integer = 10 )
    private BigDecimal entryValue;
    
    @Column(scale= 2, precision=19)
    @DecimalMin( value = "0.00" )
    @Digits( fraction = 2, integer = 10 )
    private BigDecimal parcelValue;
    
    private Integer quantityOfParcel;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date firstParcelDate;
    
    
    @ManyToOne(fetch= FetchType.EAGER)
    private Corrector corrector;
    @ManyToOne(fetch= FetchType.EAGER)
    private Honorary honorary;
    @ManyToOne
    private SystemUser systemUser;
    private Boolean honoraryIsPaid;
    @Enumerated(EnumType.STRING)
    private StatusSale statusSale;
    @OneToMany
    private List<Annex> attachments;
    private String nameOfTheWitness1;
    @CPF
    private String cpfOfTheWitness1;
    private String nameOfTheWitness2;
    @CPF
    private String cpfOfTheWitness2;
    private PaymentType paymentType;
    private BigDecimal discount;
    private DiscountType discountType;
    private BigDecimal interest;
    
    @Version
    private int version;


    public List<Annex> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<Annex> attachments) {
        this.attachments = attachments;
    }

    public Corrector getCorrector() {
        return corrector;
    }

    public void setCorrector(Corrector corrector) {
        this.corrector = corrector;
    }

    public String getCpfOfTheWitness1() {
        return cpfOfTheWitness1;
    }

    public void setCpfOfTheWitness1(String cpfOfTheWitness1) {
        this.cpfOfTheWitness1 = cpfOfTheWitness1;
    }

    public String getCpfOfTheWitness2() {
        return cpfOfTheWitness2;
    }

    public void setCpfOfTheWitness2(String cpfOfTheWitness2) {
        this.cpfOfTheWitness2 = cpfOfTheWitness2;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public BigDecimal getEntryValue() {
        return entryValue;
    }

    public void setEntryValue(BigDecimal entryValue) {
        this.entryValue = entryValue;
    }

    public Date getFirstParcelDate() {
        return firstParcelDate;
    }

    public void setFirstParcelDate(Date firstParcelDate) {
        this.firstParcelDate = firstParcelDate;
    }

    public Honorary getHonorary() {
        return honorary;
    }

    public void setHonorary(Honorary honorary) {
        this.honorary = honorary;
    }

    public Boolean getHonoraryIsPaid() {
        return honoraryIsPaid;
    }

    public void setHonoraryIsPaid(Boolean honoraryIsPaid) {
        this.honoraryIsPaid = honoraryIsPaid;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Lot getLot() {
        return lot;
    }

    public void setLot(Lot lot) {
        this.lot = lot;
    }

    public String getNameOfReference1() {
        return nameOfReference1;
    }

    public void setNameOfReference1(String nameOfReference1) {
        this.nameOfReference1 = nameOfReference1;
    }

    public String getNameOfReference2() {
        return nameOfReference2;
    }

    public void setNameOfReference2(String nameOfReference2) {
        this.nameOfReference2 = nameOfReference2;
    }

    public String getNameOfTheWitness1() {
        return nameOfTheWitness1;
    }

    public void setNameOfTheWitness1(String nameOfTheWitness1) {
        this.nameOfTheWitness1 = nameOfTheWitness1;
    }

    public String getNameOfTheWitness2() {
        return nameOfTheWitness2;
    }

    public void setNameOfTheWitness2(String nameOfTheWitness2) {
        this.nameOfTheWitness2 = nameOfTheWitness2;
    }

    public String getObservation() {
        return observation;
    }

    public void setObservation(String observation) {
        this.observation = observation;
    }

    public BigDecimal getParcelValue() {
        return parcelValue;
    }

    public void setParcelValue(BigDecimal parcelValue) {
        this.parcelValue = parcelValue;
    }

    public String getPhoneOfReference1() {
        return phoneOfReference1;
    }

    public void setPhoneOfReference1(String phoneOfReference1) {
        this.phoneOfReference1 = phoneOfReference1;
    }

    public String getPhoneOfReference2() {
        return phoneOfReference2;
    }

    public void setPhoneOfReference2(String phoneOfReference2) {
        this.phoneOfReference2 = phoneOfReference2;
    }

    public Integer getQuantityOfParcel() {
        return quantityOfParcel;
    }

    public void setQuantityOfParcel(Integer quantityOfParcel) {
        this.quantityOfParcel = quantityOfParcel;
    }

    public Date getSaleDate() {
        return saleDate;
    }

    public void setSaleDate(Date saleDate) {
        this.saleDate = saleDate;
    }

    public StatusSale getStatusSale() {
        return statusSale;
    }

    public void setStatusSale(StatusSale statusSale) {
        this.statusSale = statusSale;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public BigDecimal getTotalValue() {
        return totalValue;
    }

    public void setTotalValue(BigDecimal totalValue) {
        this.totalValue = totalValue;
    }



    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Sale other = (Sale) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.customer != other.customer && (this.customer == null || !this.customer.equals(other.customer))) {
            return false;
        }
        if ((this.nameOfReference1 == null) ? (other.nameOfReference1 != null) : !this.nameOfReference1.equals(other.nameOfReference1)) {
            return false;
        }
        if ((this.phoneOfReference1 == null) ? (other.phoneOfReference1 != null) : !this.phoneOfReference1.equals(other.phoneOfReference1)) {
            return false;
        }
        if ((this.nameOfReference2 == null) ? (other.nameOfReference2 != null) : !this.nameOfReference2.equals(other.nameOfReference2)) {
            return false;
        }
        if ((this.phoneOfReference2 == null) ? (other.phoneOfReference2 != null) : !this.phoneOfReference2.equals(other.phoneOfReference2)) {
            return false;
        }
        if ((this.observation == null) ? (other.observation != null) : !this.observation.equals(other.observation)) {
            return false;
        }
        if (this.enterprise != other.enterprise && (this.enterprise == null || !this.enterprise.equals(other.enterprise))) {
            return false;
        }
        if (this.lot != other.lot && (this.lot == null || !this.lot.equals(other.lot))) {
            return false;
        }
        if (this.saleDate != other.saleDate && (this.saleDate == null || !this.saleDate.equals(other.saleDate))) {
            return false;
        }
        if (this.totalValue != other.totalValue && (this.totalValue == null || !this.totalValue.equals(other.totalValue))) {
            return false;
        }
        if (this.entryValue != other.entryValue && (this.entryValue == null || !this.entryValue.equals(other.entryValue))) {
            return false;
        }
        if (this.parcelValue != other.parcelValue && (this.parcelValue == null || !this.parcelValue.equals(other.parcelValue))) {
            return false;
        }
        if (this.quantityOfParcel != other.quantityOfParcel && (this.quantityOfParcel == null || !this.quantityOfParcel.equals(other.quantityOfParcel))) {
            return false;
        }
        if (this.firstParcelDate != other.firstParcelDate && (this.firstParcelDate == null || !this.firstParcelDate.equals(other.firstParcelDate))) {
            return false;
        }
       
        if (this.corrector != other.corrector && (this.corrector == null || !this.corrector.equals(other.corrector))) {
            return false;
        }
        if (this.honorary != other.honorary && (this.honorary == null || !this.honorary.equals(other.honorary))) {
            return false;
        }
        if (this.systemUser != other.systemUser && (this.systemUser == null || !this.systemUser.equals(other.systemUser))) {
            return false;
        }
        if (this.honoraryIsPaid != other.honoraryIsPaid && (this.honoraryIsPaid == null || !this.honoraryIsPaid.equals(other.honoraryIsPaid))) {
            return false;
        }
        if (this.statusSale != other.statusSale) {
            return false;
        }
        if (this.attachments != other.attachments && (this.attachments == null || !this.attachments.equals(other.attachments))) {
            return false;
        }
        if ((this.nameOfTheWitness1 == null) ? (other.nameOfTheWitness1 != null) : !this.nameOfTheWitness1.equals(other.nameOfTheWitness1)) {
            return false;
        }
        if ((this.cpfOfTheWitness1 == null) ? (other.cpfOfTheWitness1 != null) : !this.cpfOfTheWitness1.equals(other.cpfOfTheWitness1)) {
            return false;
        }
        if ((this.nameOfTheWitness2 == null) ? (other.nameOfTheWitness2 != null) : !this.nameOfTheWitness2.equals(other.nameOfTheWitness2)) {
            return false;
        }
        if ((this.cpfOfTheWitness2 == null) ? (other.cpfOfTheWitness2 != null) : !this.cpfOfTheWitness2.equals(other.cpfOfTheWitness2)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 29 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 29 * hash + (this.customer != null ? this.customer.hashCode() : 0);
        hash = 29 * hash + (this.nameOfReference1 != null ? this.nameOfReference1.hashCode() : 0);
        hash = 29 * hash + (this.phoneOfReference1 != null ? this.phoneOfReference1.hashCode() : 0);
        hash = 29 * hash + (this.nameOfReference2 != null ? this.nameOfReference2.hashCode() : 0);
        hash = 29 * hash + (this.phoneOfReference2 != null ? this.phoneOfReference2.hashCode() : 0);
        hash = 29 * hash + (this.observation != null ? this.observation.hashCode() : 0);
        hash = 29 * hash + (this.enterprise != null ? this.enterprise.hashCode() : 0);
        hash = 29 * hash + (this.lot != null ? this.lot.hashCode() : 0);
        hash = 29 * hash + (this.saleDate != null ? this.saleDate.hashCode() : 0);
        hash = 29 * hash + (this.totalValue != null ? this.totalValue.hashCode() : 0);
        hash = 29 * hash + (this.entryValue != null ? this.entryValue.hashCode() : 0);
        hash = 29 * hash + (this.parcelValue != null ? this.parcelValue.hashCode() : 0);
        hash = 29 * hash + (this.quantityOfParcel != null ? this.quantityOfParcel.hashCode() : 0);
        hash = 29 * hash + (this.firstParcelDate != null ? this.firstParcelDate.hashCode() : 0);
        hash = 29 * hash + (this.corrector != null ? this.corrector.hashCode() : 0);
        hash = 29 * hash + (this.honorary != null ? this.honorary.hashCode() : 0);
        hash = 29 * hash + (this.systemUser != null ? this.systemUser.hashCode() : 0);
        hash = 29 * hash + (this.honoraryIsPaid != null ? this.honoraryIsPaid.hashCode() : 0);
        hash = 29 * hash + (this.statusSale != null ? this.statusSale.hashCode() : 0);
        hash = 29 * hash + (this.attachments != null ? this.attachments.hashCode() : 0);
        hash = 29 * hash + (this.nameOfTheWitness1 != null ? this.nameOfTheWitness1.hashCode() : 0);
        hash = 29 * hash + (this.cpfOfTheWitness1 != null ? this.cpfOfTheWitness1.hashCode() : 0);
        hash = 29 * hash + (this.nameOfTheWitness2 != null ? this.nameOfTheWitness2.hashCode() : 0);
        hash = 29 * hash + (this.cpfOfTheWitness2 != null ? this.cpfOfTheWitness2.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Sale{" + "id=" + id + ", customer=" + customer + ", nameOfReference1=" + nameOfReference1 + ", phoneOfReference1=" + phoneOfReference1 + ", nameOfReference2=" + nameOfReference2 + ", phoneOfReference2=" + phoneOfReference2 + ", observation=" + observation + ", enterprise=" + enterprise + ", lot=" + lot + ", saleDate=" + saleDate + ", totalValue=" + totalValue + ", entryValue=" + entryValue + ", parcelValue=" + parcelValue + ", quantityOfParcel=" + quantityOfParcel + ", firstParcelDate=" + firstParcelDate + ", corrector=" + corrector + ", honorary=" + honorary + ", systemUser=" + systemUser + ", honoraryIsPaid=" + honoraryIsPaid + ", statusSale=" + statusSale + ", attachments=" + attachments + ", nameOfTheWitness1=" + nameOfTheWitness1 + ", cpfOfTheWitness1=" + cpfOfTheWitness1 + ", nameOfTheWitness2=" + nameOfTheWitness2 + ", cpfOfTheWitness2=" + cpfOfTheWitness2 + ", version=" + version + '}';
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    public void setDiscount(BigDecimal discount) {
        this.discount = discount;
    }

    public DiscountType getDiscountType() {
        return discountType;
    }

    public void setDiscountType(DiscountType discountType) {
        this.discountType = discountType;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public BigDecimal getInterest() {
        return interest;
    }

    public void setInterest(BigDecimal interest) {
        this.interest = interest;
    }
    
    
    
    
    

}
